package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVo;
import com.itheima.health.vo.SetMealVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

public interface SetMealMapper extends BaseMapper<Setmeal> {
    //修改中删除第三张表的数据
    @Delete("delete from t_setmeal_checkgroup where SETMEAL_ID = #{id}")
   void updateSetmealById(@Param("id") Integer id);


//     //根据套餐id查询对应的图片信息（套餐修改图片回显）
//     @Select("select img from t_setmeal where id = #{id}")
//     String findImgById(@Param("id") Integer id);


    //添加操作
    @Insert("insert into t_setmeal_checkgroup values (#{sid},#{checkgroupId})")
    void addSetmeal(@Param("sid") Integer sid, @Param("checkgroupId") Integer checkgroupId);

    //通过套餐主键查询中间表中所有对应的检查组id
    @Select("select CHECKGROUP_ID from t_setmeal_checkgroup where SETMEAL_ID = #{sid}")
    Integer[] findCheckGroupById(@Param("sid") Integer id);


    //通过对应套餐id查询该套餐信息
    @Select("SELECT `NAME` ,REMARK , SEX , AGE , IMG " +
            "FROM t_setmeal " +
            "WHERE ID = #{id}")
    SetMealVo findSetmealById(@Param("id") int id);

    //通过套餐id查询对应的检查组信息
    @Select("SELECT tsc.CHECKGROUP_ID,tc.`NAME` ,tc.REMARK " +
            "FROM t_checkgroup tc,t_setmeal_checkgroup tsc " +
            "WHERE tsc.CHECKGROUP_ID=tc.ID and tsc.SETMEAL_ID=#{id}")
    List<CheckGroupVo> findSetmealinfoByIdAndCheckGroupList(@Param("id") Integer id);


    //根据检查组的id查询对应的检查项的信息
    @Select("select tc.`NAME` " +
            "FROM t_checkgroup_checkitem tcc,t_checkitem tc " +
            "WHERE tcc.CHECKITEM_ID=tc.ID and tcc.CHECKGROUP_ID=#{gid}")
    List<CheckItem> findCheckItemByCheckId(@Param("gid") Integer gid);

}
